<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('员工图片列表')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
    <div class="ui-layout-west">
        <div class="box box-main">
            <div class="box-header">
                <div class="box-title">
                    <i class="fa icon-grid"></i> 人员档案
                </div>
                <div class="box-tools pull-right">
                    <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新"><i class="fa fa-refresh"></i></button>
                </div>
            </div>
            <div class="ui-layout-content">
                <div id="tree" class="ztree"></div>
            </div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="container-div">
            <div class="row">
                <div class="col-sm-12 search-collapse">
                    <form id="formId">
                        <input type="hidden" id="deptId" name="deptId">
                        <input type="hidden" id="userId" name="userId">
                        <div class="select-list">
                            <ul>
                                <li>
                                    <label>员工姓名：</label>
                                    <input type="text" name="userName"/>
                                </li>
                                <li>
                                    <label>档案类型：</label>
                                    <select name="imageType" th:with="type=${@dict.getType('basic_image_type')}">
                                        <option value="">所有</option>
                                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                    </select>
                                </li>
                                <li>
                                    <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                </li>
                            </ul>
                        </div>
                    </form>
                </div>

                <div class="btn-group-sm" id="toolbar" role="group">
                    <a class="btn btn-success" onclick="add()" shiro:hasPermission="basic:image:add">
                        <i class="fa fa-plus"></i> 添加
                    </a>
                    <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="basic:image:remove">
                        <i class="fa fa-remove"></i> 删除
                    </a>
                    <a class="btn btn-success" onclick="downloadImage()" shiro:hasPermission="basic:image:download">
                        <i class="fa fa-download"></i> 下载
                    </a>
                </div>
                <div class="col-sm-12 select-table table-striped">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: layout-latest-js" />
    <th:block th:include="include :: ztree-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('basic:image:edit')}]];
        var removeFlag = [[${@permission.hasPermi('basic:image:remove')}]];
        var imageTypeDatas = [[${@dict.getType('basic_image_type')}]];
        var prefix = ctx + "basic/image";

        $(function() {
            var panehHidden = false;
            if ($(this).width() < 769) {
                panehHidden = true;
            }
            $('body').layout({ initClosed: panehHidden, west__size: 185 });
            // 回到顶部绑定
            if ($.fn.toTop !== undefined) {
                var opt = {
                    win:$('.ui-layout-center'),
                    doc:$('.ui-layout-center')
                };
                $('#scroll-up').toTop(opt);
            }
            queryImageList();
            queryUserTree();
        });

        function queryImageList() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add/{id}",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                modalName: "员工图片",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'imageId',
                    title: '档案id',
                    visible: false
                },
                {
                    title: "序号",
                    formatter: function (value, row, index) {
                        return $.table.serialNumber(index);
                    }
                },
                {
                    field: 'userNo',
                    title: '员工工号'
                },
                {
                    field: 'userName',
                    title: '员工姓名'

                },
                {
                    field: 'imageType',
                    title: '档案类型',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(imageTypeDatas, value);
                    }
                },
                {
                    field: 'imageFile',
                    title: '图片文件',
                    sortable: true
                },
                {
                    field: 'imageContent',
                    title: '缩略图',
                    formatter: function(value, row, index) {
                        return '<img width="100px;" height="100px;" src="'+value+'">';
                    }
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    field: 'createTime',
                    title: '上传日期',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.imageId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.imageId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        }

        function queryUserTree()
        {
            var url = ctx + "basic/user/treeData";
            var options = {
                url: url,
                expandLevel: 1,
                onClick : zOnClick
            };
            $.tree.init(options);

            function zOnClick(event, treeId, treeNode) {
                var type = treeNode.type;
                var id = treeNode.id;
                var treeId = id.substring(id.indexOf('_') + 1, id.length);
                if(type == 'user'){
                    $("#userId").val(treeId);
                    $("#deptId").val('');
                }else{
                    $("#userId").val('');
                    $("#deptId").val(treeId);
                }
                $.table.search();
            }
        }

        $('#btnExpand').click(function() {
            $._tree.expandAll(true);
            $(this).hide();
            $('#btnCollapse').show();
        });

        $('#btnCollapse').click(function() {
            $._tree.expandAll(false);
            $(this).hide();
            $('#btnExpand').show();
        });

        $('#btnRefresh').click(function() {
            queryUserTree();
        });

        function add(){
            var userId = $("#userId").val();
            if(userId != ''){
                $.operate.add(userId);
            }else{
                $.operate.add(0);
            }
        }

        function downloadImage(){
            var rows = $.table.selectFirstColumns();
            if (rows.length == 0) {
                var userId = $("#userId").val();
                if(userId == ''){
                    $.modal.alertError("请选择要下载图片的员工");
                    return;
                }
                $.modal.confirm("确定导出当前人员的所有电子档案吗？", function() {
                    window.location.href = prefix + "/download/" + userId;
                });
            }else{
                $.modal.confirm("确定导出当前人员的所选的" + rows.length + "份电子档案吗？", function() {
                    window.location.href = prefix + "/download?imageIds=" + rows.join();
                });
            }
        }
    </script>
</body>
</html>